#define _CRT_SECURE_NO_WARNINGS
#include "1.16_hs.h"
int cmp_struct_emp_name(const void* e1, const void* e2)
{
	return strcmp(((struct emp*)e1)->name, ((struct emp*)e2)->name);
}

int cmp_struct_emp_age(const void* e1, const void* e2)
{
	return ((struct emp*)e1)->age - ((struct emp*)e2)->age;
}

void Print_struct_emp_sz(struct emp* p, int sz)
{
	for (int i = 0; i < sz; i++)
	{
		printf("%s %d\n", (p + i)->name, (p + i)->age);
	}
}

void Swap(char* b1, char* b2,size_t width)
{
	for (int i = 0; i < width; i++)
	{
		char t = b1[i];
		b1[i] = b2[i];
		b2[i] = t;
	}
}

void my_qsort(const void* base, size_t num, size_t width, int(*p)(const void*, const void*))
{
	for (int n = 0; n < num - 1; n++)
	{
		int flag = 1;
		for (int i = 0; i < num - 1 - n; i++)
		{
			if (p((char*)base + i * width, (char*)base + (i + 1) * width) > 0)
			{
				Swap((char*)base + i * width, (char*)base + (i + 1) * width, width);
				flag = 0;
			}
		}
		if (flag == 1)
			break;
	}
}